package study.config.apollo.support.apollo.listener;

import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class Config_01_ChangeListener {

    @ApolloConfigChangeListener(value = "config.yml")
    private void configOnChange(ConfigChangeEvent changeEvent) {
        String nameSpace = changeEvent.getNamespace();
        log.info("nameSpace= {}", nameSpace);
        for (String key : changeEvent.changedKeys()) {
            ConfigChange change = changeEvent.getChange(key);

            change.getNamespace();
            change.getChangeType();
            String name = change.getPropertyName();
            String oldValue = change.getOldValue();
            String newValue = change.getNewValue();
            log.info("{}: {} >>>>>> {}", name, oldValue, newValue);
        }
    }
}
